<?php
namespace Admin\Controller;
use Think\Controller;
class KclassController extends Controller {
    //显示列表
    public function kclasslist(){
        $kclassmodel=M('kclass');
        $kclass=$kclassmodel->select();
        $this->kclass=$kclass;
        $this->display();
}
//添加列表
   function addkclass(){
        $kname=$_POST['kname'];
        $price=$_POST['price'];
        $level=$_POST['level'];
        $ktime=$_POST['ktime'];
        $kclass=D('kclass');     
        if ($kclass->create()) 
        {
            if (false !== $kclass->add()) {
                //echo $user->getLastSql();
                $this->success('添加成功！', 'kclasslist');
            }
            else
            {
                $this->error('添加失败，数据错误','kclasslist');
            }
        }
            $this->display();
        }

//        function delkclass(){
//         $jid=$_POST['jid'];
//         $kclass=M("kclass");
//         $kclassdata=$kclass->where('jid='.$jid)->find();
//         unlink('./Public/upload/'.$kclassdata['pic']);
//         if(false!=$kclass->where('jid='.$jid)->delete()){
//             $result['msg']=1;
//             $this->ajaxReturn($result);
//         }else{
//             $result['msg']=0;
//             $this->ajaxReturn($result);
//         }
// }

    // }
        //删除课程
        function delkclass(){
        $kid=I('get.id');
        $data=M('kclass')->where(array('kid'=>$kid))->find();
        if($data){
            
                $re=M('kclass')->where(array('kid'=>$kid))->delete();
            if($re)
                $this->success('删除成功！','kclasslist');
            else
                $this->error('删除失败！','kclasslist');
        }else
            $this->error('课程信息意外丢失，删除失败！');
        }

      //显示修改课程
    function kclassmod(){
            $kid = $_GET['id'];
            $re = M('kclass')->where('kid='.$kid)->find();
            $this->re = $re;
            $this->display();
        }
//修改课程
        function kclassmod1(){
            //$class = M("class");
            $kid = $_POST['kid'];
            $data['kname']=$_POST['kname'];
            $data['price'] = $_POST['price'];
            $data['level'] = $_POST['level'];
            $data['ktime'] = $_POST['ktime'];
            
            $int = M('kclass')->where('kid='.$kid)->save($data);
            if($int){
                $this->success('修改成功！','kclasslist');
            }
            else{
                echo "$data";
                $this->error('修改失败！','kclasslist');
            }
    
        }
   
   //搜索课程列表
     //       public function searchkclass(){
     //    $key = $_GET['key'];
     //    $kclassnum = M('kclass')->where('kname like "%'.$key.'%"')->count();
     //    $Page = new \Think\Page($kclassnum,2);
     //    $this->kclassnum =$kclassnum;
     //    $this->kclasspage=$Page->show();
     //    if (kclassnum) {
     //    $this->clublist=M('kclass')
     //        ->where('kname like "%'.$key.'%"')
     //        ->order('kid')
     //        ->limit($Page->firstRow,2)
     //        ->select();
     //    }
     // else $this->error('没有相关信息！');
     //    }  
          public function searchkclass(){
        $key=$_POST['kname'];
        //echo "$key";
        $search=M('kclass');
        $search=$search->where("kname like '%$key%'" )->select();
        $this->search=$search;
    
        $this->display();
   }
         
}